%h1 New Video
-semantic_form_for(:video, @video, :url=>user_videos_path(user_session.user_id)) do |form|
  #loading-indicator{:style=>"display:none"}
    =image_tag("ajax-loader.gif")
  
  =form.error_messages
  -form.inputs do
    =form.input :url
    #inline_error_message
    =form.input :title
    =form.input :description
  -form.buttons do
    =form.commit_button :label=>t(:register_user)
    


%script{:type => "text/javascript", :charset => "utf-8"}
  //To where make the request
  var serverUrl = '#{discover_video_info_path}/';
  :plain
    $('video_url').observe('change', updatevideoInfo);
    
    function updatevideoInfo(event) {
      $('loading-indicator').show();
      $('video_title').disabled = true;
      $('video_description').disabled = true;
      
      
      encodedUri = serverUrl+'?url='+encodeURIComponent($('video_url').value);
      new Ajax.Request(encodedUri, 
          {asynchronous:true, 
           evalScripts:true, 
           onLoaded:function(){ responseLoaded() },
           onSuccess:function(request){ updateVideo(request)} 
          });
    }
  
    function updateVideo(request){
      if (!request.responseJSON.error) {
        $('video_title').value = request.responseJSON.title;
        $('video_description').value = request.responseJSON.description
      } else {
        $('inline_error_message').innerHTML = request.responseJSON.error;
      }
    }
    
    function responseLoaded() {
      $('loading-indicator').hide();
      $('video_title').disabled = false;
      $('video_description').disabled = false;
    }
  
    